﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Gift.DBUtility;//Please add references

using Gift.Model;
using AjaxPro;
namespace Gift.DAL
{
    /// <summary>
    /// 数据访问类:DALUser
    /// </summary>
    public partial class DALUser
    {
        public DALUser()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from tbUser");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
            parameters[0].Value = id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Gift.Model.tbUser model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into tbUser(");
            strSql.Append("userRank,userName,userPwd,email,registerTime,registerIP,parentUser,modifyTime,lastLoginTime,lastLoginIP,loginCount,money,frozenMoney,payPoints,rankPoints,question,answer,nickName,sex,telephone,fax,mobile,address,qq,msn,wangwang,state)");
            strSql.Append(" values (");
            strSql.Append("@userRank,@userName,@userPwd,@email,@registerTime,@registerIP,@parentUser,@modifyTime,@lastLoginTime,@lastLoginIP,@loginCount,@money,@frozenMoney,@payPoints,@rankPoints,@question,@answer,@nickName,@sex,@telephone,@fax,@mobile,@address,@qq,@msn,@wangwang,@state)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@userRank", SqlDbType.Int,4),
					new SqlParameter("@userName", SqlDbType.NVarChar,20),
					new SqlParameter("@userPwd", SqlDbType.NVarChar,200),
					new SqlParameter("@email", SqlDbType.NVarChar,50),
					new SqlParameter("@registerTime", SqlDbType.DateTime),
					new SqlParameter("@registerIP", SqlDbType.NVarChar,20),
					new SqlParameter("@parentUser", SqlDbType.Int,4),
					new SqlParameter("@modifyTime", SqlDbType.DateTime),
					new SqlParameter("@lastLoginTime", SqlDbType.DateTime),
					new SqlParameter("@lastLoginIP", SqlDbType.NVarChar,20),
					new SqlParameter("@loginCount", SqlDbType.Int,4),
					new SqlParameter("@money", SqlDbType.Decimal,9),
					new SqlParameter("@frozenMoney", SqlDbType.Decimal,9),
					new SqlParameter("@payPoints", SqlDbType.Int,4),
					new SqlParameter("@rankPoints", SqlDbType.Int,4),
					new SqlParameter("@question", SqlDbType.NVarChar,100),
					new SqlParameter("@answer", SqlDbType.NVarChar,100),
					new SqlParameter("@nickName", SqlDbType.NVarChar,20),
					new SqlParameter("@sex", SqlDbType.Bit,1),
					new SqlParameter("@telephone", SqlDbType.NVarChar,50),
					new SqlParameter("@fax", SqlDbType.NVarChar,50),
					new SqlParameter("@mobile", SqlDbType.NVarChar,50),
					new SqlParameter("@address", SqlDbType.NVarChar,200),
					new SqlParameter("@qq", SqlDbType.NVarChar,50),
					new SqlParameter("@msn", SqlDbType.NVarChar,50),
					new SqlParameter("@wangwang", SqlDbType.NVarChar,50),
					new SqlParameter("@state", SqlDbType.Bit,1)};
            parameters[0].Value = model.userRank;
            parameters[1].Value = model.userName;
            parameters[2].Value = model.userPwd;
            parameters[3].Value = model.email;
            parameters[4].Value = model.registerTime;
            parameters[5].Value = model.registerIP;
            parameters[6].Value = model.parentUser;
            parameters[7].Value = model.modifyTime;
            parameters[8].Value = model.lastLoginTime;
            parameters[9].Value = model.lastLoginIP;
            parameters[10].Value = model.loginCount;
            parameters[11].Value = model.money;
            parameters[12].Value = model.frozenMoney;
            parameters[13].Value = model.payPoints;
            parameters[14].Value = model.rankPoints;
            parameters[15].Value = model.question;
            parameters[16].Value = model.answer;
            parameters[17].Value = model.nickName;
            parameters[18].Value = model.sex;
            parameters[19].Value = model.telephone;
            parameters[20].Value = model.fax;
            parameters[21].Value = model.mobile;
            parameters[22].Value = model.address;
            parameters[23].Value = model.qq;
            parameters[24].Value = model.msn;
            parameters[25].Value = model.wangwang;
            parameters[26].Value = model.state;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Gift.Model.tbUser model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update tbUser set ");
            strSql.Append("userRank=@userRank,");
            strSql.Append("userName=@userName,");
            strSql.Append("userPwd=@userPwd,");
            strSql.Append("email=@email,");
            strSql.Append("registerTime=@registerTime,");
            strSql.Append("registerIP=@registerIP,");
            strSql.Append("parentUser=@parentUser,");
            strSql.Append("modifyTime=@modifyTime,");
            strSql.Append("lastLoginTime=@lastLoginTime,");
            strSql.Append("lastLoginIP=@lastLoginIP,");
            strSql.Append("loginCount=@loginCount,");
            strSql.Append("money=@money,");
            strSql.Append("frozenMoney=@frozenMoney,");
            strSql.Append("payPoints=@payPoints,");
            strSql.Append("rankPoints=@rankPoints,");
            strSql.Append("question=@question,");
            strSql.Append("answer=@answer,");
            strSql.Append("nickName=@nickName,");
            strSql.Append("sex=@sex,");
            strSql.Append("telephone=@telephone,");
            strSql.Append("fax=@fax,");
            strSql.Append("mobile=@mobile,");
            strSql.Append("address=@address,");
            strSql.Append("qq=@qq,");
            strSql.Append("msn=@msn,");
            strSql.Append("wangwang=@wangwang,");
            strSql.Append("state=@state,");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@userRank", SqlDbType.Int,4),
					new SqlParameter("@userName", SqlDbType.NVarChar,20),
					new SqlParameter("@userPwd", SqlDbType.NVarChar,200),
					new SqlParameter("@email", SqlDbType.NVarChar,50),
					new SqlParameter("@registerTime", SqlDbType.DateTime),
					new SqlParameter("@registerIP", SqlDbType.NVarChar,20),
					new SqlParameter("@parentUser", SqlDbType.Int,4),
					new SqlParameter("@modifyTime", SqlDbType.DateTime),
					new SqlParameter("@lastLoginTime", SqlDbType.DateTime),
					new SqlParameter("@lastLoginIP", SqlDbType.NVarChar,20),
					new SqlParameter("@loginCount", SqlDbType.Int,4),
					new SqlParameter("@money", SqlDbType.Decimal,9),
					new SqlParameter("@frozenMoney", SqlDbType.Decimal,9),
					new SqlParameter("@payPoints", SqlDbType.Int,4),
					new SqlParameter("@rankPoints", SqlDbType.Int,4),
					new SqlParameter("@question", SqlDbType.NVarChar,100),
					new SqlParameter("@answer", SqlDbType.NVarChar,100),
					new SqlParameter("@nickName", SqlDbType.NVarChar,20),
					new SqlParameter("@sex", SqlDbType.Bit,1),
					new SqlParameter("@telephone", SqlDbType.NVarChar,50),
					new SqlParameter("@fax", SqlDbType.NVarChar,50),
					new SqlParameter("@mobile", SqlDbType.NVarChar,50),
					new SqlParameter("@address", SqlDbType.NVarChar,200),
					new SqlParameter("@qq", SqlDbType.NVarChar,50),
					new SqlParameter("@msn", SqlDbType.NVarChar,50),
					new SqlParameter("@wangwang", SqlDbType.NVarChar,50),
					new SqlParameter("@state", SqlDbType.Bit,1),
					new SqlParameter("@id", SqlDbType.Int,4)};
            parameters[0].Value = model.userRank;
            parameters[1].Value = model.userName;
            parameters[2].Value = model.userPwd;
            parameters[3].Value = model.email;
            parameters[4].Value = model.registerTime;
            parameters[5].Value = model.registerIP;
            parameters[6].Value = model.parentUser;
            parameters[7].Value = model.modifyTime;
            parameters[8].Value = model.lastLoginTime;
            parameters[9].Value = model.lastLoginIP;
            parameters[10].Value = model.loginCount;
            parameters[11].Value = model.money;
            parameters[12].Value = model.frozenMoney;
            parameters[13].Value = model.payPoints;
            parameters[14].Value = model.rankPoints;
            parameters[15].Value = model.question;
            parameters[16].Value = model.answer;
            parameters[17].Value = model.nickName;
            parameters[18].Value = model.sex;
            parameters[19].Value = model.telephone;
            parameters[20].Value = model.fax;
            parameters[21].Value = model.mobile;
            parameters[22].Value = model.address;
            parameters[23].Value = model.qq;
            parameters[24].Value = model.msn;
            parameters[25].Value = model.wangwang;
            parameters[26].Value = model.state;
            parameters[27].Value = model.id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from tbUser ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
            parameters[0].Value = id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from tbUser ");
            strSql.Append(" where id in (" + idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Gift.Model.tbUser GetModel(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,userRank,userName,userPwd,email,registerTime,registerIP,parentUser,modifyTime,lastLoginTime,lastLoginIP,loginCount,money,frozenMoney,payPoints,rankPoints,question,answer,nickName,sex,telephone,fax,mobile,address,qq,msn,wangwang,state  from tbUser ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
            parameters[0].Value = id;

            Gift.Model.tbUser model = new Gift.Model.tbUser();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["userRank"] != null && ds.Tables[0].Rows[0]["userRank"].ToString() != "")
                {
                    model.userRank = int.Parse(ds.Tables[0].Rows[0]["userRank"].ToString());
                }
                if (ds.Tables[0].Rows[0]["userName"] != null && ds.Tables[0].Rows[0]["userName"].ToString() != "")
                {
                    model.userName = ds.Tables[0].Rows[0]["userName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["userPwd"] != null && ds.Tables[0].Rows[0]["userPwd"].ToString() != "")
                {
                    model.userPwd = ds.Tables[0].Rows[0]["userPwd"].ToString();
                }
                if (ds.Tables[0].Rows[0]["email"] != null && ds.Tables[0].Rows[0]["email"].ToString() != "")
                {
                    model.email = ds.Tables[0].Rows[0]["email"].ToString();
                }
                if (ds.Tables[0].Rows[0]["registerTime"] != null && ds.Tables[0].Rows[0]["registerTime"].ToString() != "")
                {
                    model.registerTime = DateTime.Parse(ds.Tables[0].Rows[0]["registerTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["registerIP"] != null && ds.Tables[0].Rows[0]["registerIP"].ToString() != "")
                {
                    model.registerIP = ds.Tables[0].Rows[0]["registerIP"].ToString();
                }
                if (ds.Tables[0].Rows[0]["parentUser"] != null && ds.Tables[0].Rows[0]["parentUser"].ToString() != "")
                {
                    model.parentUser = int.Parse(ds.Tables[0].Rows[0]["parentUser"].ToString());
                }
                if (ds.Tables[0].Rows[0]["modifyTime"] != null && ds.Tables[0].Rows[0]["modifyTime"].ToString() != "")
                {
                    model.modifyTime = DateTime.Parse(ds.Tables[0].Rows[0]["modifyTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["lastLoginTime"] != null && ds.Tables[0].Rows[0]["lastLoginTime"].ToString() != "")
                {
                    model.lastLoginTime = DateTime.Parse(ds.Tables[0].Rows[0]["lastLoginTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["lastLoginIP"] != null && ds.Tables[0].Rows[0]["lastLoginIP"].ToString() != "")
                {
                    model.lastLoginIP = ds.Tables[0].Rows[0]["lastLoginIP"].ToString();
                }
                if (ds.Tables[0].Rows[0]["loginCount"] != null && ds.Tables[0].Rows[0]["loginCount"].ToString() != "")
                {
                    model.loginCount = int.Parse(ds.Tables[0].Rows[0]["loginCount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["money"] != null && ds.Tables[0].Rows[0]["money"].ToString() != "")
                {
                    model.money = decimal.Parse(ds.Tables[0].Rows[0]["money"].ToString());
                }
                if (ds.Tables[0].Rows[0]["frozenMoney"] != null && ds.Tables[0].Rows[0]["frozenMoney"].ToString() != "")
                {
                    model.frozenMoney = decimal.Parse(ds.Tables[0].Rows[0]["frozenMoney"].ToString());
                }
                if (ds.Tables[0].Rows[0]["payPoints"] != null && ds.Tables[0].Rows[0]["payPoints"].ToString() != "")
                {
                    model.payPoints = int.Parse(ds.Tables[0].Rows[0]["payPoints"].ToString());
                }
                if (ds.Tables[0].Rows[0]["rankPoints"] != null && ds.Tables[0].Rows[0]["rankPoints"].ToString() != "")
                {
                    model.rankPoints = int.Parse(ds.Tables[0].Rows[0]["rankPoints"].ToString());
                }
                if (ds.Tables[0].Rows[0]["question"] != null && ds.Tables[0].Rows[0]["question"].ToString() != "")
                {
                    model.question = ds.Tables[0].Rows[0]["question"].ToString();
                }
                if (ds.Tables[0].Rows[0]["answer"] != null && ds.Tables[0].Rows[0]["answer"].ToString() != "")
                {
                    model.answer = ds.Tables[0].Rows[0]["answer"].ToString();
                }
                if (ds.Tables[0].Rows[0]["nickName"] != null && ds.Tables[0].Rows[0]["nickName"].ToString() != "")
                {
                    model.nickName = ds.Tables[0].Rows[0]["nickName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sex"] != null && ds.Tables[0].Rows[0]["sex"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["sex"].ToString() == "1") || (ds.Tables[0].Rows[0]["sex"].ToString().ToLower() == "true"))
                    {
                        model.sex = true;
                    }
                    else
                    {
                        model.sex = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["telephone"] != null && ds.Tables[0].Rows[0]["telephone"].ToString() != "")
                {
                    model.telephone = ds.Tables[0].Rows[0]["telephone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["fax"] != null && ds.Tables[0].Rows[0]["fax"].ToString() != "")
                {
                    model.fax = ds.Tables[0].Rows[0]["fax"].ToString();
                }
                if (ds.Tables[0].Rows[0]["mobile"] != null && ds.Tables[0].Rows[0]["mobile"].ToString() != "")
                {
                    model.mobile = ds.Tables[0].Rows[0]["mobile"].ToString();
                }
                if (ds.Tables[0].Rows[0]["address"] != null && ds.Tables[0].Rows[0]["address"].ToString() != "")
                {
                    model.address = ds.Tables[0].Rows[0]["address"].ToString();
                }
                if (ds.Tables[0].Rows[0]["qq"] != null && ds.Tables[0].Rows[0]["qq"].ToString() != "")
                {
                    model.qq = ds.Tables[0].Rows[0]["qq"].ToString();
                }
                if (ds.Tables[0].Rows[0]["msn"] != null && ds.Tables[0].Rows[0]["msn"].ToString() != "")
                {
                    model.msn = ds.Tables[0].Rows[0]["msn"].ToString();
                }
                if (ds.Tables[0].Rows[0]["wangwang"] != null && ds.Tables[0].Rows[0]["wangwang"].ToString() != "")
                {
                    model.wangwang = ds.Tables[0].Rows[0]["wangwang"].ToString();
                }
                if (ds.Tables[0].Rows[0]["state"] != null && ds.Tables[0].Rows[0]["state"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["state"].ToString() == "1") || (ds.Tables[0].Rows[0]["state"].ToString().ToLower() == "true"))
                    {
                        model.state = true;
                    }
                    else
                    {
                        model.state = false;
                    }
                }
   
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,userRank,userName,userPwd,email,registerTime,registerIP,parentUser,modifyTime,lastLoginTime,lastLoginIP,loginCount,money,frozenMoney,payPoints,rankPoints,question,answer,nickName,sex,telephone,fax,mobile,address,qq,msn,wangwang,state  ");
            strSql.Append(" FROM tbUser ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" id,userRank,userName,userPwd,email,registerTime,registerIP,parentUser,modifyTime,lastLoginTime,lastLoginIP,loginCount,money,frozenMoney,payPoints,rankPoints,question,answer,nickName,sex,telephone,fax,mobile,address,qq,msn,wangwang,state  ");
            strSql.Append(" FROM tbUser ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM tbUser ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.id desc");
            }
            strSql.Append(")AS Row, T.*  from tbUser T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }


        [AjaxMethod]
        public bool DetectionUser(string userName)
        {
            bool flag = true;
            try
            {
                string commandText = string.Format("select count(id) as [count] from tbUser where userName=@userName", new object[0]);
                SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@userName", userName) };

                using (SqlDataReader dr = DbHelperSQL.ExecuteReader(commandText, commandParameters))
                {
                    if (dr.Read())
                    {
                        if (dr.GetInt32(0) == 1)
                        {
                            flag = false;
                            // 
                        }
                        dr.Close();
                    }
                }
            }
            catch
            {
            }
            return flag;
        }

        public DataTable GetAllUserEmail()
        {
            DataTable table = new DataTable();
            try
            {
                string commandText = string.Format("select id,userName,email from tbUser ", new object[0]);
              
                table = DbHelperSQL.Query(commandText).Tables[0];
            }
            catch
            {
            }
            return table;
        }

        public DataTable GetUserById(int id)
        {
            DataTable table = new DataTable();
            try
            {
                string commandText = string.Format("select a.id,userRank,rankName,userName,email,convert(nvarchar(10),registerTime,121) as registerTime,registerIP,[money],payPoints,question,answer,nickName,sex,telephone,fax,mobile,address,qq,msn,wangwang,state from tbUser a left join tbUserRank b on a.userRank=b.id where a.id=@id", new object[0]);
                SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@id", id) };
                table = DbHelperSQL.Query(commandText, commandParameters).Tables[0];
            }
            catch
            {
            }
            return table;
        }





        public bool ModifyUserPwd(tbUser user)
        {
            bool flag = true;
            try
            {
                string commandText = string.Format("update tbUser set userPwd=@userPwd where id=@id", new object[0]);
                SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@userPwd", user.userPwd), new SqlParameter("@id", user.id) };
                if (DbHelperSQL.ExecuteSql(commandText, commandParameters) <= 0)
                {
                    flag = false;
                }
            }
            catch
            {
            }
            return flag;
        }

        public bool ModifyUserQuestion(tbUser user)
        {
            bool flag = true;
            try
            {
                string commandText = string.Format("update tbUser set question=@question,answer=@answer where id=@id", new object[0]);
                SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@question", user.question), new SqlParameter("@answer", user.answer), new SqlParameter("@id", user.id) };
                if (DbHelperSQL.ExecuteSql(commandText, commandParameters) <= 0)
                {
                    flag = false;
                }
            }
            catch
            {
            }
            return flag;
        }

        public DataTable UserLogin(tbUser user)
        {
            DataTable table = new DataTable();
            try
            {
                string commandText = string.Format("select a.id,userRank as rankId,rankName,userName,userPwd,email,[money],payPoints,state from tbUser a left join tbUserRank b on a.userRank=b.id where userName=@userName and userPwd=@userPwd", new object[0]);
                SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@userName", user.userName), new SqlParameter("@userPwd", user.userPwd) };
                table = DbHelperSQL.Query( commandText, commandParameters).Tables[0];
            }
            catch
            {
            }
            return table;
        }

        public int UserRegister(tbUser user)
        {
            int num = 0;
            try
            {
                string commandText = string.Format("insert into tbUser(userRank,userName,userPwd,email,registerIP ) values(@userRank,@userName,@userPwd,@email,@registerIP) select @@identity as id", new object[0]);
                SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@userRank", user.userRank), new SqlParameter("@userName", user.userName), new SqlParameter("@userPwd", user.userPwd), new SqlParameter("@email", user.email), new SqlParameter("@registerIP", user.registerIP) };
                num = DbHelperSQL.ExecuteSql(commandText, commandParameters);

            }
            catch
            {
            }
            return num;
        }

        public bool ModifyUserMoneyAndPayPoints(tbUser user)
        {
            bool flag = false;
            try
            {
                string commandText = string.Format("update tbUser set [money]=@money,payPoints=@payPoints where id=@id", new object[0]);
                SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@money", user.money), new SqlParameter("@payPoints", user.payPoints), new SqlParameter("@id", user.id) };
                if (DbHelperSQL.ExecuteSql(commandText, commandParameters) > 0)
                {
                    flag = true;
                }
            }
            catch
            {
            }
            return flag;
        }




        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "tbUser";
            parameters[1].Value = "id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

